var dashboard = {};

//获取一周前的日期
function GetStartTime() {
　　 //let date =  new Date(new Date().getTime()- 6 * 24 * 60* 60 * 1000); //获取一周前的日期
	let date =  new Date();	//当前时间
    let year = date.getFullYear(); 　//返回的是年份
    let month = date.getMonth() + 1; //返回的是月份 记得+1 才是当前月 （从0开始 0代表1月） 
	if (month < 10) {
		month = "0" + month;
	}
　  let dates = date.getDate()　　　　//返回的是日 date上面定义了 这里命名为 dates
	if (dates < 10) {
		dates = "0" + dates;
	}
      //let day = date.getDay();　　　　　//返回的是周几
    // console.log(year.toString().padStart(4,'0')+month+day);
    //console.log(year.toString()+'-' + month.toString()+'-' +dates.toString()); //输出时将年月日转换为 字符串 形式，不然三个数字会进行相加，导致值错误
	var strdate = year.toString() + "-" + month.toString() + "-" + dates.toString()+"T00:00:00";
	return strdate;
}

function GetLastWeek() {
　　 let date =  new Date(new Date().getTime()- 6 * 24 * 60* 60 * 1000); //获取一周前的日期
    let year = date.getFullYear(); 　//返回的是年份
    let month = date.getMonth() + 1; //返回的是月份 记得+1 才是当前月 （从0开始 0代表1月） 
	if (month < 10) {
		month = "0" + month;
	}
　  let dates = date.getDate()　　　　//返回的是日 date上面定义了 这里命名为 dates
	if (dates < 10) {
		dates = "0" + dates;
	}
      //let day = date.getDay();　　　　　//返回的是周几
    // console.log(year.toString().padStart(4,'0')+month+day);
    //console.log(year.toString()+'-' + month.toString()+'-' +dates.toString()); //输出时将年月日转换为 字符串 形式，不然三个数字会进行相加，导致值错误
	var strdate = year.toString() + "-" + month.toString() + "-" + dates.toString()+"T00:00:00";
	return strdate;
}

//控制ecahrt中标题的显示长度
function controlShowLength(params, length){
        if (length != null) {
            params = params.substring(0, length);
        }
        var newParamsName = "";// 最终拼接成的字符串
        var paramsNameNumber = params.length;// 实际标签的个数
        var provideNumber = 4;// 每行能显示的字的个数
        var rowNumber = Math.ceil(paramsNameNumber / provideNumber);// 换行的话，需要显示几行，向上取整
        /**
          * 判断标签的个数是否大于规定的个数， 如果大于，则进行换行处理 如果不大于，即等于或小于，就返回原标签
          */
        // 条件等同于rowNumber>1
        if (paramsNameNumber > provideNumber) {
            /** 循环每一行,p表示行 */
            for (var p = 0; p < rowNumber; p++) {
                var tempStr = "";// 表示每一次截取的字符串
                var start = p * provideNumber;// 开始截取的位置
                var end = start + provideNumber;// 结束截取的位置
                // 此处特殊处理最后一行的索引值
                if (p == rowNumber - 1) {
                    // 最后一次不换行
                    tempStr = params.substring(start, paramsNameNumber);
                } else {
                    // 每一次拼接字符串并换行
                    tempStr = params.substring(start, end) + "\n";
                }
               newParamsName += tempStr;// 最终拼成的字符串
            }
        } else {
             // 将旧标签的值赋给新标签
            newParamsName = params;
        }
        //将最终的字符串返回
        return newParamsName
}

//左边顶部横向柱状图
dashboard.TransverseBarLh = function () {
	var urls = location.search;
	if (urls.indexOf("?") != -1) {
		urls = urls.replace("?", "&");
	}
	//var argslist = MapToUrl();
    var dtime = [];
	var datas = [];
	var title = [];
	var myTBarChart = echarts.init(document.getElementById('TransverseBarLh'),'walden');
	Tbaroption = null;	
	//$.get('http://192.168.100.25/datav/TransverseBarLh.json' + urls, function (data) {
	var sTimes = GetStartTime();
	//$.get('/metric/v3/V3Line?starttime='+sTimes+'&intv=day&dfmat=MM-dd&etype=bar&stack=total'+urls, function (data) {
	$.get('/metric/v2/V2Bar?key=logType&starttime='+sTimes+urls, function (data) {
		title = data.title;
		dtime = data.dtime;
		datas = data.subvalue;
		myTBarChart.setOption(Tbaroption = {
			backgroundColor: '',
			/*
			title: {
				text: '一周类型告警',
				//subtext: '纯属虚构',
				top:'1%',
				x: 'center'
			},
			*/
		    tooltip : {
		        trigger: 'axis',
		        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
		            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
		        }
		    },
			/*
		    legend: {
				top:'9%',
		        data: title
		    },
			*/
		    grid: {
				top:'20',
		        left: '3%',
		        right: '6%',
		        bottom: '30',
		        containLabel: true
		    },
		    xAxis:  {             //xAxis 和 yAxis 决定bar的类型是横向还是纵向
		        type: 'value',
       			splitLine: {
           			show: true,
           			lineStyle:{
               			opacity:0.2
           			}
	        	}					
		    },
		    yAxis: {
		        type: 'category',
		        data: title,
				axisLabel:{  
                    formatter : function(params){
                        return controlShowLength(params, 8);
                    }
				},
       			splitLine: {
           			show: true,
           			lineStyle:{
               			opacity:0.2
           			}
	        	}					
		    },
		    series: datas
		});
	});

//    var currentIndex = -1;
//    setInterval(function() {
//        var dataLength= Tbaroption.series[0].data.length;
//        currentIndex = (currentIndex + 1) % dataLength;
//        myTBarChart.dispatchAction({
//            type: 'showTip',
//            seriesIndex: 0,
//            dataIndex: currentIndex
//        });
//    }, 2800);
    
	setInterval(function () {
		$.get('/metric/v2/V2Bar?key=logType&starttime='+sTimes+urls, function (data) {
			title = data.title;
			dtime = data.dtime;
			datas = data.subvalue;
			myTBarChart.setOption(Tbaroption,true);	
		});
	},301000);		
}

//左边底部表格
dashboard.RollPageTableLb22 = function () {
	var urls = location.search;
	if (urls.indexOf("?") != -1) {
		urls = urls.replace("?", "&");
	}
	//var argslist = MapToUrl();
		layui.use('table', function () {
			var table = layui.table;			
				var tableIns = table.render({
					elem: '#RollPageTableLb',
					//limit: '10',
					//height: 350,
					skin: 'nob',					
					width: '400',
					even: true,
					//size: 'sm',
					//limits: [10, 20, 30],
					url: '/metric/v2/V2Dist?key=clientIp&logType=waf'+urls,
					//cellMinWidth: 80,
					cols: [
						[
							{
								field: 'xuhao',
								type:'numbers',
								title: '序号'
							},						
							{
								field: 'name',
								title: 'IP'
							}, {
								field: 'value',
								title: '次数'
							}, {
								field: 'remarks',
								title: '城市'
							}
						]
					],
					id:'RollPageTableLb',
					page: false,
					done:function(res,curr,count){	       
	       				$('th').css({'background-color':'rgba(11,15,51,1)','color':'#fff'})
						//var that = this.elem.next();
						var index = 0;
						res.data.forEach(function() {
							//console.log(index % 2);
							index++;
							//console.log(index)
							if (index % 2 == 0){
								$('tr').eq(index).css({'background-color':'rgba(11,15,51,1)','color':'#fff'})
							}else{
								$('tr').eq(index).css({'background-color':'rgba(11,15,51,0.9)','color':'#fff'})
							}
						})
						     
	    			}
				});
			setInterval(function () {		
			    tableIns.reload('RollPageTableLb',{});
			},302000);
		});	
}

dashboard.RollPageTableLb = function () {
	var urls = location.search;
	if (urls.indexOf("?") != -1) {
		urls = urls.replace("?", "&");
	}
	//var argslist = MapToUrl();
	$.get('/metric/v2/V2Dist?key=clientIp&logType=waf'+urls, function (datas) {
		var html = "";
		var jsondatas = eval(datas.data);
		$.each(jsondatas, function (i, item) {
			if ( i%2 == 0 ) {
				//html += '<tr align="center" height="35px" ><td align="center" width=45%>' + jsondatas[i].name + '</td><td align="center" width=20%>' + jsondatas[i].value + '</td><td align="center" width=25%>' + jsondatas[i].ratio + '%</td></tr>';
				html += '<tr style="background-color:rgba(11,15,51, 0.9);color:#fff"><td>'+(i+1)+'</td><td>' + jsondatas[i].name + '</td><td>' + jsondatas[i].value + '</td><td>' + jsondatas[i].remarks + '</td></tr>';				
	        }else{
				html += '<tr style="background-color:#0B0F33;color:#fff"><td>'+(i+1)+'</td><td>' + jsondatas[i].name + '</td><td>' + jsondatas[i].value + '</td><td>' + jsondatas[i].remarks + '</td></tr>';				
			}
			//$("#RollPageTableLb").append(html);
		});
		$("#RollPageTableLb").append(html);
	});
}

dashboard.RollPageTableLb11 = function () {
	var urls = location.search;
	if (urls.indexOf("?") != -1) {
		urls = urls.replace("?", "&");
	}
	//var argslist = MapToUrl();
	$.get('/metric/v2/V2Dist?key=clientIp&logType=reqlimit'+urls, function (datas) {
		var html = "";
		var jsondatas = eval(datas.data);
		$.each(jsondatas, function (i, item) {
			if ( i%2 == 0 ) {
				//html += '<tr align="center" height="35px" ><td align="center" width=45%>' + jsondatas[i].name + '</td><td align="center" width=20%>' + jsondatas[i].value + '</td><td align="center" width=25%>' + jsondatas[i].ratio + '%</td></tr>';
				html += '<tr style="background-color:rgba(11,15,51, 0.9);color:#fff"><td>'+(i+1)+'</td><td>' + jsondatas[i].name + '</td><td>' + jsondatas[i].value + '</td><td>' + jsondatas[i].remarks + '</td></tr>';				
	        }else{
				html += '<tr style="background-color:#0B0F33;color:#fff"><td>'+(i+1)+'</td><td>' + jsondatas[i].name + '</td><td>' + jsondatas[i].value + '</td><td>' + jsondatas[i].remarks + '</td></tr>';				
			}
			//$("#RollPageTableLb").append(html);
		});
		$("#RollPageTableLb11").append(html);
	});
}

Date.prototype.format = function(format) {
    /*
     * eg:format="YYYY-MM-dd hh:mm:ss";
     * new Date().format("yyyy.MM.dd");

     */
    var o = {
        "M+" :this.getMonth() + 1, // month
        "d+" :this.getDate(), // day
        "h+" :this.getHours(), // hour
        "m+" :this.getMinutes(), // minute
        "s+" :this.getSeconds(), // second
        "q+" :Math.floor((this.getMonth() + 3) / 3), // quarter
        "S" :this.getMilliseconds()
    // millisecond
    }
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "")
                .substr(4 - RegExp.$1.length));
    }
    for ( var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
                    : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}

//////////////
//中间底部动态曲线
dashboard.DynamicLine = function () {
	var urls = location.search;
	if (urls.indexOf("?") != -1) {
		urls = urls.replace("?", "&");
	}
	//var argslist = MapToUrl();
    var dtime = [];
	var datas = [];
	var runInterval = 300000; //5分
	var ndayz = new Date(new Date().toLocaleDateString()).format("yyyy-MM-ddThh:mm:ss");
	var myDtLineChart = echarts.init(document.getElementById('DatavDynamicLine'),'walden');
	lineoption = null;	
	$.get('/metric/v1/V1Line?starttime=' + ndayz+ urls, function (data) {
		dtime = data.dtime;
		datas = data.subvalue[0].data;
		myDtLineChart.setOption(lineoption = {
			backgroundColor: '',
			tooltip: {
        		trigger: 'axis'
    		},
		    grid: {
				top: '20',
		        left: '7%',
		        right: '3%',
		        bottom: '50',
		        containLabel: false
		    },			
		    xAxis: {
		        type: 'category',
				//type: 'time',
		        boundaryGap: false,
		        data: dtime,
       			splitLine: {
           			show: true,
           			lineStyle:{
               			opacity:0.2
           			}
	        	}				
		    },
		    yAxis: {
		        type: 'value',
		        boundaryGap: [0, '100%'],
       			splitLine: {
           			show: true,
           			lineStyle:{
               			opacity:0.2
           			}
	        	}				
		    },
    		series: [{
        		data: datas,
        		type: 'line'
    		}]
		});
	});
	setInterval(function () {
		var nowtimestamp = new Date().getTime();
		var sTime = nowtimestamp - runInterval
		//{name: "16:12",value: 22746}
		$.get('/metric/v1/V1Line?starttime=' + sTime, function (data) {
         	dtime.push(data.name);
		 	datas.push(data.value);
			myDtLineChart.setOption(lineoption,true);	
		});
	},runInterval);		
}

//中间地图region
dashboard.ChinaMapRegion = function () {
	var urls = location.search;
	if (urls.indexOf("?") != -1) {
		urls = urls.replace("?", "&");
	}
	var chinaMapChart = echarts.init(document.getElementById('chinaMapRegion'));
	mapOption = null;
	$.get('/metric/v1/ChinaMap?area=region'+ urls,function(data) {
		console.log(data);
		chinaMapChart.setOption(
		mapOption = {
		    backgroundColor: '',
		    title: {
		        text: '\n\n攻击来源分布',
		        //subtext: data.msg,
		        //sublink: 'http://www.pm25.in',
		        x:'center',
		        textStyle: {
					fontSize: 20,
		            color: '#fff'
		        }
		    },
			//mapValueCalculation: 'average', 
		    tooltip : {
		        trigger: 'item'
		    },
		    legend: {
		        orient: 'vertical',
		        y: 'bottom',
		        x:'right',
		        data:['攻击分布'],
		        textStyle: {
		            color: '#fff'
		        }
		    },
		    visualMap: {
		        min: 0,
		        max: data.max,
		        calculable: true,
		        inRange: {
		            color: ['#68ccc8', '#2f76b0', '#354af0']
		        },
		        textStyle: {
		            color: '#fff'
		        }
		    },
			/*
		    toolbox: {
		        show: true,
		        orient : 'vertical',
		        x: 'right',
		        y: 'center',
		        feature : {
		            mark : {show: true},
		            dataView : {show: true, readOnly: false},
		            restore : {show: true},
		            saveAsImage : {show: true}
		        }
		    },
			*/
		    series : [
		        {
		            name: '攻击城市分布',
		            type: 'map',
		            mapType: 'china',
					zoom:1.2,
		            roam: true,								
		            itemStyle:{
		                normal:{
             			borderColor: "#112b3b", //省市边界线
             			borderColor: "#a7e4e6", //省市边界线
             			shadowColor: 'rgba(166, 230, 236, 0.6)',
             			shadowOffsetX: 0,
             			shadowOffsetY: 0,
             			shadowBlur: 30,							
		                    label:{
		                        show:true,
								formatter:'{b}:{c}',
		                        textStyle: {
		                           color: "rgb(249, 249, 249)"
		                        }
		                    }
		                },
		                emphasis:{label:{show:true}}
		            },
		            data:data.data
		        }
		    ]
		});
	});
}

/////////////////
//右边顶部区域曲线图
dashboard.AreaLineRh = function () {
	var urls = location.search;
	if (urls.indexOf("?") != -1) {
		urls = urls.replace("?", "&");
	}
	//var argslist = MapToUrl();
    var dtime = [];
	var datas = [];
	var runInterval = 30000; //5分
	var myALineChart = echarts.init(document.getElementById('AreaLineRh'),'walden');
	alineoption = null;	
	$.get('/metric/v3/V3Line'+ location.search, function (data) {
		title = data.title;
		dtime = data.dtime;
		datas = data.subvalue;
		myALineChart.setOption(alineoption = {
			backgroundColor: '',
			/*
			title: {
				text: '流量图[Mbps]'
			},
			*/
			tooltip: {
				trigger: 'axis'
			},
			legend: {
				data: title
			},			
			grid: {
				top:'20',
				left: '3%',
				right: '4%',
				bottom: '50',
				containLabel: true
			},
			/*
			toolbox: {
				feature: {
					saveAsImage: {}
				}
			},
			*/
			xAxis: {
				type: 'category',
				boundaryGap: false,
				data: dtime,
       			splitLine: {
           			show: true,
           			lineStyle:{
               			opacity:0.2
           			}
	        	}				
			},
			yAxis: {
				type: 'value',
       			splitLine: {
           			show: true,
           			lineStyle:{
               			opacity:0.2
           			}
	        	}				
			},
			series: datas
		});
	});
	/*
    var currentIndex = -1;
    setInterval(function() {
        var dataLength= alineoption.series[0].data.length;
        currentIndex = (currentIndex + 1) % dataLength;
        // 显示 tooltip
        myALineChart.dispatchAction({
            type: 'showTip',
            seriesIndex: 0,
            dataIndex: currentIndex
        });
    }, 2200);
    */
	setInterval(function () {
		var nowtimestamp = new Date().getTime();
		var sTime = nowtimestamp - runInterval
		$.get('/metric/v3/V3Line' +location.search, function (data) {
			//title = data.title;
			dtime = data.dtime;
			datas = data.subvalue;
			myALineChart.setOption(alineoption,true);	
		});
	},runInterval);		
}

//右边中间竖直纵向柱状图
dashboard.VerticalBarRm = function () {
	var urls = location.search;
	if (urls.indexOf("?") != -1) {
		urls = urls.replace("?", "&");
	}
	//var argslist = MapToUrl();
    var dtime = [];
	var datas = [];
	var title = [];
	var myZBarChart = echarts.init(document.getElementById('VerticalBarRm'),'walden');
	Zbaroption = null;	
	var sTimes = GetLastWeek();
	//$.get('/metric/v3/V3Line?starttime='+sTimes+'&intv=day&dfmat=MM-dd&etype=bar&stack=total' + urls, function (data) { //stack=total为堆叠，否则独立柱形
	$.get('/metric/v3/V3Line?starttime='+sTimes+'&intv=day&dfmat=MM-dd&etype=bar' + urls, function (data) {
		title = data.title;
		dtime = data.dtime;
		datas = data.subvalue;
		myZBarChart.setOption(Zbaroption = {
			backgroundColor: '',
			/*
    		toolbox: {
        		feature: {
        			magicType: {  
        			show: true,
            
					title:"切换",
					type: ['line', 'bar','stack'],
				},
        		restore: {},
        		saveAsImage: {}
        		}
    		},	
			*/		
		    tooltip : {
		        trigger: 'axis',
		        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
		            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
		        }
		    },
			/*
		    legend: {
				top:'9%',
		        data:title
		    },
			*/
		    grid: {
				top: '20',
		        left: '12%',
		        right: '4%',
		        bottom: '50',
		        containLabel: false
		    },
		    xAxis : [     //xAxis 和 yAxis 决定bar的类型是横向还是纵向
		        {
		            type : 'category',
		            data : dtime,				
        			splitLine: {
            			show: true,
            			lineStyle:{
                			opacity:0.2
            			}
		        	}
				}	
		    ],
		    yAxis : [
		        {
		            type : 'value',
        			splitLine: {
            			show: true,
            			lineStyle:{
                			opacity:0.2
            			}
		        	}					
		        }
		    ],
		    series : datas
		});
	});
    var currentIndex = -1;
    setInterval(function() {
        var dataLength= Zbaroption.series[0].data.length;
        // 取消之前高亮的图形
        /*
        myZBarChart.dispatchAction({
            type: 'downplay',
            seriesIndex: 0,
            dataIndex: currentIndex
        });
        */
        currentIndex = (currentIndex + 1) % dataLength;
        // 高亮当前图形
		/*
        myZBarChart.dispatchAction({
            type: 'highlight',
            seriesIndex: 0,
            dataIndex: currentIndex
        });
        */
        // 显示 tooltip
        myZBarChart.dispatchAction({
            type: 'showTip',
            seriesIndex: 0,
            dataIndex: currentIndex
        });
    }, 2800);	
	setInterval(function () {
		$.get('/metric/v3/V3Line?starttime='+sTimes+'&intv=day&dfmat=MM-dd&etype=bar&stack=total' + urls, function (data) {
			title = data.title;
			dtime = data.dtime;
			datas = data.subvalue;
			myZBarChart.setOption(Zbaroption,true);	
		});
	},302000);		
}

//右边底部空心饼图
dashboard.HollowPieRb = function () {
	var urls = location.search;
	if (urls.indexOf("?") != -1) {
		urls = urls.replace("?", "&");
	}
	//var argslist = MapToUrl();
    var dname = [];
	var datas = [];
	var myHPieChart = echarts.init(document.getElementById('HollowPieRb'),'walden');
	hpieoption = null;	

	$.get('/metric/v2/V2Dist?key=attackType&logType=waf'+urls, function (data) {
		dname = data.name;
		datas = data.data;
		myHPieChart.setOption(hpieoption = {
			backgroundColor: '',
		    tooltip: {
		        trigger: 'item',
		        formatter: "{a} <br/>{b}: {c} ({d}%)"
		    },
			/*
		    legend: {
		        orient: 'vertical',
		        x: 'left',
				y: '18%',
		        data:dname
		    },
			*/
		    series: [
		        {
		            name:'web安全',
		            type:'pie',
					center: ['50%', '50%'],
		        	x: '3%',
		            radius: ['60%', '80%'],
		            avoidLabelOverlap: false,
		            label: {
		                normal: {
		                    show: false,
		                    position: 'center'
		                },
		                emphasis: {
		                    show: true,
		                    textStyle: {
		                        fontSize: '16',
		                        fontWeight: 'bold'
		                    },
							formatter: "{b}:\n{c} ({d}%)"
		                }
		            },
		            labelLine: {
		                normal: {
		                    show: false
		                }
		            },
		            data:datas
		        }
		    ]
		});
	});
//循环高亮	
    var currentIndex = -1;
    setInterval(function() {
        var dataLength= hpieoption.series[0].data.length;
        // 取消之前高亮的图形
        myHPieChart.dispatchAction({
            type: 'downplay',
            seriesIndex: 0,
            dataIndex: currentIndex
        });
        currentIndex = (currentIndex + 1) % dataLength;
        // 高亮当前图形
        myHPieChart.dispatchAction({
            type: 'highlight',
            seriesIndex: 0,
            dataIndex: currentIndex
        });
        // 显示 tooltip
        /*
        myHPieChart.dispatchAction({
            type: 'showTip',
            seriesIndex: 0,
            dataIndex: currentIndex
        });
        */
    }, 2700);
 //定期更新图表    	
	setInterval(function () {	
		$.get('/metric/v2/V2Dist?key=attackType&logType=waf' + urls , function (data) {
			dname = data.name;
			datas = data.data;
			myHPieChart.setOption(hpieoption,true);				
		});	
	},303000);
}

//右边底部实心饼图
dashboard.SolidPieRb2 = function () {
	var urls = location.search;
	if (urls.indexOf("?") != -1) {
		urls = urls.replace("?", "&");
	}
	//var argslist = MapToUrl();
    var dname = [];
	var datas = [];
	var mySPieChart = echarts.init(document.getElementById('SolidPieRb2'),'walden');
	/*
	mySPieChart.showLoading({
		text: 'loading',
		color: '#c23531',
		textColor: '#000',
		maskColor: 'rgba(255, 255, 255, 0.8)',
		zlevel: 0
	});
	*/
	spieoption = null;			
	$.get('/metric/v2/V2Dist?key=attackType&logType=reqlimit'+ urls, function (data) {	
		dname = data.name;
		datas = data.data;	
		mySPieChart.setOption(spieoption = {
			backgroundColor: '',
		    tooltip : {
		        trigger: 'item',
		        formatter: "{a} <br/>{b} : {c} ({d}%)"
		    },
			/*
		    legend: {
		        orient: 'vertical',
				y: '18%',
		        left: 'right',
		        data: dname
		    },
			*/
		    series : [
		        {
		            name: '防刷限流',
		            type: 'pie',
		            radius : '75%',
		            center: ['50%', '50%'],
		            data:datas,
		            itemStyle: {						
		                emphasis: {
		                    shadowBlur: 10,
		                    shadowOffsetX: 0,
		                    shadowColor: 'rgba(0, 0, 0, 0.5)'
		                }
		            },
		            label: {
		                normal: {
		                    show: false,
		                    position: 'inside'
		                },
		                emphasis: {
		                    show: true,
		                    textStyle: {
		                        fontSize: '14',
		                        fontWeight: 'bold'
		                    },							
							formatter: "{b}:\n{c} ({d}%)"
		                }
		            }					
		        }
		    ]
		});
	});
	//mySPieChart.hideLoading();
//循环高亮
    var currentIndex = -1;
    setInterval(function() {
        var dataLength= spieoption.series[0].data.length;
        // 取消之前高亮的图形
        mySPieChart.dispatchAction({
            type: 'downplay',
            seriesIndex: 0,
            dataIndex: currentIndex
        });
        currentIndex = (currentIndex + 1) % dataLength;
        // 高亮当前图形
        mySPieChart.dispatchAction({
            type: 'highlight',
            seriesIndex: 0,
            dataIndex: currentIndex
        });
        // 显示 tooltip
        /*
        mySPieChart.dispatchAction({
            type: 'showTip',
            seriesIndex: 0,
            dataIndex: currentIndex
        });
        */
    }, 3800);
//定期更新图表    
	setInterval(function () {	
		$.get('/metric/v2/V2Dist?key=attackType&logType=reqlimit'+urls, function (data) {
			dname = data.name;
			datas = data.data;
			mySPieChart.setOption(spieoption,true);				
		});	
	},303000);	
}

//后台首页曲线
dashboard.MainLine = function () {
	var urls = location.search;
	if (urls.indexOf("?") != -1) {
		urls = urls.replace("?", "&");
	}
	//var argslist = MapToUrl();
    var dtime = [];
	var datas = [];
	var runInterval = 30000; //5分
	var myALineChart = echarts.init(document.getElementById('mainLine'),'walden');
	alineoption = null;	
	$.get('/metric/v3/V3Line'+ location.search, function (data) {
		title = data.title;
		dtime = data.dtime;
		datas = data.subvalue;
		myALineChart.setOption(alineoption = {
			backgroundColor: '',
			/*
			title: {
				text: '流量图[Mbps]'
			},
			*/
			tooltip: {
				trigger: 'axis'
			},
			legend: {
				data: title
			},			
			grid: {
				top:'20',
				left: '3%',
				right: '4%',
				bottom: '50',
				containLabel: true
			},
			/*
			toolbox: {
				feature: {
					saveAsImage: {}
				}
			},
			*/
			xAxis: {
				type: 'category',
				boundaryGap: false,
				data: dtime,
       			splitLine: {
           			show: true,
           			lineStyle:{
               			opacity:0.2
           			}
	        	}				
			},
			yAxis: {
				type: 'value',
       			splitLine: {
           			show: true,
           			lineStyle:{
               			opacity:0.2
           			}
	        	}				
			},
			series: datas
		});
	});
}
